/**
 * @author temsa
 * @name Archetype.component.historyComponent
 * @class Archetype.component.historyComponent
 * Describes the Standard Component Interface
 */
Archetype.Component.create(
/** @scope Archetype.component.historyComponent.prototype */
{
	/**
	 * Name of the component.
	 * Your component will only be available if this is filled with the good classpath
	 */
	name : "Archetype.component.historyComponent",
	/**
	 * Set up the Component dependencies
	 * The component won't launch main() unless
	 *  every dependencies in the setup are available
	 */
	setup : {
		dependencies:{lib:["Archetype.libs.rsh.rsh"]}
	},
	/**
	 * Allow configuration transformation before prototypize phase
	 */
	beforeInstanciate: function() {
    	if(typeof this.setup == "undefined") {
        	this.setup = {};
        }
    	if(typeof this.setup.events != "undefined") {
        	$A(this.setup.events).each(function(eventName) {
        		var eventNameWithUpperCase = eventName.substr(0, 1).toUpperCase() + eventName.substr(1);
        		this["on" + eventNameWithUpperCase] = function(data) {
        			if(!this.rshEvent) {
        				window.dhtmlHistory.add(eventName, data);
        			}
        		}.bind(this)
        	}.bind(this));
        }
	},
	/**
     * @function
     * Default empty constructor
     */
    initialize: function() {
		this.mutex = false;
		window.dhtmlHistory.create({
	        toJSON: function(o) {
				return Object.toJSON(o);
	        },
	        fromJSON: function(s) {
	        	return s.evalJSON();
	        }
		});
		window.dhtmlHistory.initialize();
		window.dhtmlHistory.addListener(this.rshListener);
	},
	rshListener: function(eventName, data) {
		this.rshEvent = true;
		this.fire(eventName, data);
		this.rshEvent = false;
	}
});